package com.meteor.downloader.videodownloader.utils

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.XXPermissions
import com.hjq.permissions.permission.PermissionLists
import com.hjq.permissions.permission.base.IPermission
import com.meteor.downloader.videodownloader.clueft.MdmTokenMeans

object PermissionMdmUtils {
    private val mdmPostPermissionType = PermissionLists.getPostNotificationsPermission()

    fun getNotifyStatus(context: Context): Boolean {
        return XXPermissions.isGrantedPermission(context, mdmPostPermissionType)
    }

    fun getNotifyPermissionApply(activity: AppCompatActivity, tilBack: (Boolean) -> Unit) {
        if (getNotifyStatus(activity)) {
            tilBack(true)
        } else {
            XXPermissions.with(activity).permission(mdmPostPermissionType)
                .request(object : OnPermissionCallback {
                    override fun onGranted(permissions: List<IPermission?>, allGranted: Boolean) {
                        MdmTokenMeans.getMdmTokenValue(activity)
                        tilBack(true)
                    }

                    override fun onDenied(permissions: List<IPermission?>, doNotAskAgain: Boolean) {
                        tilBack(false)
                    }
                })
        }
    }
}